package com.caijin.web.controller.system;


import com.caijin.common.core.domain.Result;
import com.caijin.common.core.domain.dto.ClazzDTO;
import com.caijin.common.core.domain.entity.Clazz;
import com.caijin.system.service.IClazzService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 班级 基本业务处理
 *
 * @author Peas
 * @since 2021-01-18
 */
@RestController
@RequestMapping("/system/clazz")
@CrossOrigin
public class ClazzController {

    @Autowired
    private IClazzService clazzService;

    /**
     * 创建班级
     */
    @ApiOperation(value = "创建班级")
    @RequestMapping(path = "/createClazz", method = RequestMethod.POST)
    public Result createClazz(@RequestBody Clazz clazz) {
        return clazzService.createClazz(clazz);
    }

    /**
     * 学生加入班级
     */
    @ApiOperation(value = "学生加入班级")
    @RequestMapping(path = "/joinClazz", method = RequestMethod.POST)
    public Result joinClazz(@RequestParam("invitationCode") String invitationCode,
                            @RequestParam("sno") Long sno) {
        return clazzService.joinClazz(invitationCode, sno);
    }

    /**
     * 获取课程的班级列表
     */
    @ApiOperation(value = "获取课程的班级列表")
    @RequestMapping(path = "/getClazzList", method = RequestMethod.GET)
    public Result getClazzList(@RequestParam("cno") Long cno) {
        return clazzService.getClazzListByCno(cno);
    }

    /**
     * 获取班级的学生列表
     */
    @ApiOperation(value = "获取班级的学生列表")
    @RequestMapping(path = "/getStudentList", method = RequestMethod.GET)
    public Result getStudentList(@RequestParam("clazzId") Long clazzId) {
        return clazzService.getStudentList(clazzId);
    }

    /**
     * 修改班级信息
     */
    @ApiOperation(value = "修改班级信息")
    @RequestMapping(path = "/modified", method = RequestMethod.POST)
    public Result modifiedClazz(@RequestBody ClazzDTO clazzDTO) {
        return clazzService.modifiedClazz(clazzDTO);
    }

    /**
     * 删除班级
     */
    @ApiOperation(value = "删除班级")
    @RequestMapping(path = "/delete", method = RequestMethod.GET)
    public Result deleteClazz(@RequestParam("id") Long id) {
        return clazzService.deleteClazz(id);
    }
}

